// 时间复杂度是O(n) 同时创建了新的数组
let array = [2, 3, 1, 5, 7, 3, 7, 9]
let arr = []
array.forEach(element => {
  if (arr.indexOf(element) === -1) {
    arr.push(element)
  }
})
console.log(arr)


// 双向for循环，不增加额外数组 T=O(n2)
let array = [2, 3, 1, 5, 7, 3, 7, 9]
let arr = []
for (let i = 0; i < array.length; i++) {
  for (let j = i + 1; j < array.length; j++) {
    if (array[j] === array[i])
      array.splice(j, 1)
  }
}
console.log(array)


// 使用Set
let array = [2, 3, 1, 5, 7, 3, 7, 9]
let arr = []
let set = new Set
array.forEach(element =>
  arr = [...set.add(element)]
)
console.log(arr)


// 使用Map
let array = [2, 3, 1, 5, 7, 3, 7, 9]
let arr = []
let map = new Map
array.forEach(element => {
  if (!map.has(element)) {
    map.set(element, element)
    arr.push(element)
  }
})
console.log(arr)


